package com.dayuanit.dy16.atm.task;

import com.dayuanit.dy16.atm.entity.TransferOrder;
import com.dayuanit.dy16.atm.enums.TransferOrderStatusEnums;
import com.dayuanit.dy16.atm.mapper.TransferOrderMapper;
import com.dayuanit.dy16.atm.service.ITransferDelayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class TransferRollbackTask extends BaseTask {

    @Autowired
    private ITransferDelayService transferDelayService;

    @Autowired
    private TransferOrderMapper transferOrderMapper;

    @Scheduled(cron = "0/5 * * * * ?")
    @Override
    protected void doTask() {
        processRollback();
    }

    private void processRollback() {
        List<TransferOrder> transferOrders = transferOrderMapper.listOrders(TransferOrderStatusEnums.rollback_transfer.getK());
        for (TransferOrder order : transferOrders) {
            try {
                transferDelayService.transferRollback(order);
            } catch (Exception e) {
                e.printStackTrace();
                //TODO 此处如果有异常，可以考虑将此订单转移到线下处理，有财务人员进行订单跟踪。
            }
        }
    }
}
